{% extends 'layout.html' %}
{% from 'macro/page.html' import render_pagination %}

{% block main %}
<div class="card">
    <div class="card-header">
        <div class="card-title">
            <a class="btn btn-info btn-sm" href="{{ url_for('admins.link_create') }}">新增</a>
        </div>
        <div class="card-tools">
            <form>
                <div class="input-group input-group-sm" style="width: 150px;">
                    <input type="text" name="title" class="form-control float-right"
                           value="{{ request.args['title'] }}"
                           placeholder="Search">
                    <div class="input-group-append">
                        <button type="submit" class="btn btn-default"><i class="fas fa-search"></i></button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <!-- /.card-header -->
    <form name="list_form" method="post" action="">
        <div class="card-body table-responsive p-0" style="height: 580px;">
            <table class="table table-hover table-head-fixed">
                <thead>
                <tr>
                    <th>网站名称</th>
                    <th>网站URL</th>
                    <th>负责人</th>
                    <th>联络暗号</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {% for item in record.items %}
                <tr>
                    <td>{{ item.site_name }}</td>
                    <td>{{ item.site_url }}</td>
                    <td>{{ item.site_person }}</td>
                    <td>{{ item.site_contact }}</td>
                    <td>{{ item.status_text }}</td>
                    <td>
                        <a class="btn btn-info btn-sm"
                           href="{{ url_for('admins.link_modify', link_id=item.id, next=request.full_path) }}">
                            修改
                        </a>
                        <button type="button"
                                data-url="{{ url_for('admins.link_delete', link_id=item.id, next=request.full_path) }}"
                                data-title="{{ item.site_name }}"
                                data-toggle="modal"
                                data-target="#exampleModalCenter"
                                class="btn btn-danger btn-sm">删除
                        </button>
                    </td>
                </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
        <!-- /.card-body -->
        <div class="card-footer clearfix">
            {{ render_pagination(record) }}
        </div>
    </form>
</div>
    <!-- /.modal-dialog -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog"
         aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
    <div class="modal-dialog  modal-dialog-centered" role="document">
        <div class="modal-content message_align">
            <div class="modal-header">
                <h5 class="modal-title">提示</h5>
                <button type="button" class="close" data-dismiss="modal"
                        aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">
                <p>确认删除？</p>
            </div>
            <div class="modal-footer">
                <form name="my_form" id="my_form" action="" method="post">
                    <button type="submit" class="btn btn-danger">删除</button>
                    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
                </form>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
</div>
    <!-- /.modal-dialog -->
{% endblock %}

{% block script %}
    {{ super() }}
    <script>
        $(function () {
            $('#exampleModalCenter').on('show.bs.modal', function (event) {
                let button = $(event.relatedTarget)
                let title = button.data('title')
                let url = button.data('url')
                let model = $(this)
                model.find('.modal-title').text(title)
                model.find('#my_form').attr('action', url)
            })
        })
    </script>
{% endblock %}